#include "PinholeCamera.h"

namespace Pandora
{

	void CPinholeCamera::Init()
	{
		CVector3 u = direction.Cross(up);
		u.Normalize();
		CVector3 v = direction.Cross(u);
		v.Normalize();

		dx = ((2.0f*tanf(fovx))/(float)outputWidth) * u;
		dy = ((2.0f*tanf(fovy))/(float)outputHeight) * v;

		direction.Normalize();
	}

	void CPinholeCamera::CalculateRayDirection(CRay& ray, float x, float y)
	{
		CVector3 dir = direction + ((2.0f * x + 1.0f - (float)outputWidth) * 0.5f) * dx + ((2.0f * y + 1.0f - (float)outputHeight) * 0.5f) * dy;
		dir.Normalize();
		ray.SetDirection(dir);
	}

}; //namespace Pandora